package cn.hsa.xxx.bookData.controller;


import cn.hsa.hsaf.core.framework.HsafController;
import cn.hsa.hsaf.core.framework.web.WrapperResponse;
import cn.hsa.xxx.api.dto.BookTypeDTO;
import cn.hsa.xxx.api.service.BookTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/web/bookData/bookType")
@RestController
@Slf4j
public class BookTypeController extends HsafController {

    @Autowired
    private BookTypeService bookTypeService;

    @PostMapping("/addBookType")
    public WrapperResponse<BookTypeDTO> addBookType(@RequestBody BookTypeDTO bookTypeDTO) {
        BookTypeDTO result = bookTypeService.add(bookTypeDTO);
        return WrapperResponse.success(result);
    }

    @PostMapping("/deleteBookType")
    public WrapperResponse<String> deleteBookType(@RequestParam String id) {
        String result = bookTypeService.delete(id);
        return WrapperResponse.success(result);
    }

    @GetMapping("/getBookTypeById")
    public WrapperResponse<BookTypeDTO> getBookType(@RequestParam String id) {
        BookTypeDTO result = bookTypeService.get(id);
        return WrapperResponse.success(result);
    }

    @PostMapping("/updateBookType")
    public WrapperResponse<String> updateBookType(@RequestBody BookTypeDTO bookTypeDTO) {
        String str = bookTypeService.update(bookTypeDTO);
        return WrapperResponse.success(str);
    }

    @GetMapping("/page")
    public WrapperResponse<List<BookTypeDTO>> getPageBookType(int pageNo, int pageSize) {
        List<BookTypeDTO> bookTypeDTOList = bookTypeService.getPage(pageNo, pageSize);
        return WrapperResponse.success(bookTypeDTOList);
    }
}
